package com.salinity.kun.model;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class HydrologicalDataList {
	public enum DataItem{DATE,H,VELOCITY_AVG,SALINITY_AVG};
	private List<HydrologicalData> hydrologicalDataList;
	private Map<DataItem, Object []> CacheMap;
	
	public HydrologicalDataList(List<HydrologicalData> hydrologicalDataList) {
		this.hydrologicalDataList = hydrologicalDataList;
		CacheMap = new HashMap<>();
	}
	
	public List<HydrologicalData> getList(){
		return hydrologicalDataList;
	}
	

	public Object[] getItem(DataItem dataItem) {
		
		if(CacheMap.containsKey(dataItem)) {
			return CacheMap.get(dataItem);
		}
		
		Object[] itemArray;
		int index = 0;
		switch(dataItem) {
		case DATE:
			itemArray = new String[hydrologicalDataList.size()];
			while(index<itemArray.length ) {
				itemArray[index] = hydrologicalDataList.get(index).getDate();
				index++;
			}		
			break;
		case H:
			itemArray = new Double[hydrologicalDataList.size()];
			while(index<itemArray.length ) {
				itemArray[index] = hydrologicalDataList.get(index).getH();
				index++;
			}
			break;
		case SALINITY_AVG:
			itemArray = new Double[hydrologicalDataList.size()];
			while(index<itemArray.length ) {
				itemArray[index] = hydrologicalDataList.get(index).getSalinityAvg();
				index++;
			}
			break;
		case VELOCITY_AVG:
			itemArray = new Double[hydrologicalDataList.size()];
			while(index<itemArray.length ) {
				itemArray[index] = hydrologicalDataList.get(index).getVelocityAvg();
				index++;
			}
			break;
			default:
				itemArray =null;
				break;
		}
		CacheMap.put(dataItem, itemArray);
		return itemArray;
	}
	
}
